﻿using LitJson;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public abstract class BaseNodeDataSerializor : INodeDataSerializor
{
    public virtual INodeData DeSerializeData(string json)
    {
        INodeData node = new NodeData();
        JsonData data = JsonMapper.ToObject(json);
        NodeDataDeSerialize(data, ref node);

        return node;
    }

    protected void NodeDataDeSerialize(JsonData jsonData ,ref INodeData node)
    {
        int taskDataType = jsonData["TaskDataType"].AsInt;
        if (taskDataType!=TaskDataType.None)
        {
            ITaskDataSerializor serializor = BehaviorSystem.TaskDataSerilizors[taskDataType];
            node.TaskArgs = serializor.DeSerializeData(jsonData["TaskArgs"].ToJson());
        }

        node.CurNodeState = (BehaviorNodeState)jsonData["NodeState"].AsInt;
        node.CurNodeType = jsonData["NodeType"].AsInt;
    }

    public virtual string SerializeData(INodeData nodeData)
    {
        return null;
    }
}